package com.minimalist.basic.controller.lindi;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.minimalist.common.config.mybatis.bo.PageResp;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcredit.LindiTradeApplicationCreditQueryVO;
import com.minimalist.common.entity.lindi.vo.tradeapplicationcredit.LindiTradeApplicationCreditVO;
import com.minimalist.common.feign.client.lindi.LindiTradeApplicationCreditFeignClient;
import com.minimalist.common.response.R;
import com.minimalist.common.utils.Add;
import com.minimalist.common.utils.Update;

import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

/**
 * 林地指标交易平台_交易申请付款凭证控制器
 *
 * @author 11987
 */
@Validated
@RestController
@Tag(name = "林地指标交易平台_交易申请付款凭证管理")
@RequestMapping("/basic/lindi/tradeApplicationCredit")
public class LindiTradeApplicationCreditController{

    @Autowired
    private LindiTradeApplicationCreditFeignClient feignClient;

    @PostMapping("/addTradeApplicationCredit")
    @Operation(summary = "添加交易申请付款凭证")
    @SaCheckPermission("lindi:tradeApplicationCredit:add")
    public R<?> addTradeApplicationCredit(
            @RequestBody @Validated(Add.class) LindiTradeApplicationCreditVO
                    tradeApplicationCreditVO){
        tradeApplicationCreditVO.setCreateId(StpUtil.getLoginIdAsLong());
        tradeApplicationCreditVO.setUpdateId(StpUtil.getLoginIdAsLong());
        LocalDateTime now = LocalDateTime.now();
        tradeApplicationCreditVO.setCreateTime(now);
        tradeApplicationCreditVO.setUpdateTime(now);
        return feignClient.addTradeApplicationCredit(tradeApplicationCreditVO);
    }

    @DeleteMapping("/deleteTradeApplicationCreditByTradeApplicationCreditId")
    @Operation(summary = "删除交易申请付款凭证 -> 根据交易申请付款凭证ID删除")
    @SaCheckPermission("lindi:tradeApplicationCredit:delete")
    public R<?> deleteTradeApplicationCreditByTradeApplicationCreditId(
            @RequestParam("tradeApplicationCreditId")
            @NotNull(message = "交易申请付款凭证ID不能为空")
            @Parameter(name = "tradeApplicationCreditId", required = true, description = "交易申请付款凭证ID")
            Long tradeApplicationCreditId){
        return feignClient.deleteTradeApplicationCreditByTradeApplicationCreditId(
                tradeApplicationCreditId);
    }

    @PutMapping("/updateTradeApplicationCreditByTradeApplicationCreditId")
    @Operation(summary = "修改交易申请付款凭证")
    @SaCheckPermission("lindi:tradeApplicationCredit:update")
    public R<?> updateTradeApplicationCreditByTradeApplicationCreditId(
            @RequestBody @Validated(Update.class) LindiTradeApplicationCreditVO
                    tradeApplicationCreditVO){
        tradeApplicationCreditVO.setUpdateId(StpUtil.getLoginIdAsLong());
        tradeApplicationCreditVO.setUpdateTime(LocalDateTime.now());
        return feignClient.updateTradeApplicationCreditByTradeApplicationCreditId(tradeApplicationCreditVO);
    }

    @GetMapping("/getPageTradeApplicationCreditList")
    @Operation(summary = "查询交易申请付款凭证列表(分页)")
    @SaCheckPermission("lindi:tradeApplicationCredit:get")
    public R<PageResp<LindiTradeApplicationCreditVO>> getPageTradeApplicationCreditList(
            LindiTradeApplicationCreditQueryVO queryVO){
        return feignClient.getPageTradeApplicationCreditList(queryVO);
    }

    @GetMapping("/getTradeApplicationCreditByTradeApplicationCreditId/{tradeApplicationCreditId}")
    @Operation(summary = "根据交易申请付款凭证ID查询交易申请付款凭证")
    @SaCheckPermission("lindi:tradeApplicationCredit:get")
    public R<LindiTradeApplicationCreditVO> getTradeApplicationCreditByTradeApplicationCreditId(
            @PathVariable(value = "tradeApplicationCreditId")
            @NotNull(message = "交易申请付款凭证ID不能为空")
            @Parameter(name = "tradeApplicationCreditId", description = "交易申请付款凭证ID", required = true)
            Long tradeApplicationCreditId){
        return feignClient.getTradeApplicationCreditByTradeApplicationCreditId(tradeApplicationCreditId);
    }

    @GetMapping("/getTradeApplicationCreditListByTradeApplicationId/{tradeApplicationId}")
    @Operation(summary = "根据交易申请ID查询交易申请付款凭证列表")
    @SaCheckPermission("lindi:tradeApplicationCredit:get")
    public R<List<LindiTradeApplicationCreditVO>> getTradeApplicationCreditListByTradeApplicationId(
            @PathVariable(value = "tradeApplicationId")
            @NotNull(message = "交易申请ID不能为空")
            @Parameter(name = "tradeApplicationId", description = "交易申请ID", required = true)
            Long tradeApplicationId){
        return feignClient.getTradeApplicationCreditListByTradeApplicationId(tradeApplicationId);
    }
}